<template>
  <div id="addResume" class="person-detail">
    <div>
      <van-nav-bar
        title="添加简历"
        :fixed="true"
        left-arrow
        @click-left="back"
      />
    </div>
    <div class="addResume-body">
      <van-cell-group>
        <van-cell
          :center="true"
          is-link
          @click.native="goav(detailsList[0].value)"         
          class="first-cell"
        >
          <template slot="title">
            <span class="custom-text">{{ detailsList[0].label }}</span>
            <img
              :src="detailsList[0].value"
              alt=""
              style="width:2em;height:2em;border-radius:50%;display: block;float: right;"
            />
          </template>
        </van-cell>
        <van-field
          v-model="detailsList[1].value"
          rows="1"
          autosize
          :label="detailsList[1].label"
          placeholder="请输入姓名"
          input-align="right"
        />
        <van-field
          v-model="detailsList[2].value"
          rows="1"
          autosize
          :label="detailsList[2].label"
          placeholder="请输入手机号"
          input-align="right"
        />
        <van-field
          v-model="detailsList[3].value"
          rows="1"
          autosize
          :label="detailsList[3].label"
          input-align="right"
          placeholder="请输入身份证号"
        />
        <van-field
          v-model="detailsList[4].value"
          rows="1"
          autosize
          :label="detailsList[4].label"
          input-align="right"
          placeholder="请输入年龄"
        />
        <van-field
          rows="1"
          :label="detailsList[5].label"
          autosize
          input-align="right"
        >
          <template slot="input">
            <van-radio-group v-model="detailsList[5].value">
              <van-radio checked-color="#DC4630" name="1">男</van-radio>
              <van-radio checked-color="#DC4630" name="2">女</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          v-model="detailsList[6].value"
          rows="1"
          autosize
          :label="detailsList[6].label"
          is-link
          @click="showAddress()"
        />
        <van-field
          v-model="detailsList[7].value"
          rows="1"
          autosize
          :label="detailsList[7].label"
          input-align="right"
          placeholder="请输入详细地址"
        />
        <van-field
          v-model="detailsList[8].value"
          rows="1"
          autosize
          :label="detailsList[8].label"
          input-align="right"
          is-link
          @click="educationShow = true"
        />
        <van-field
          v-model="detailsList[9].value"
          rows="1"
          autosize
          :label="detailsList[9].label"
          input-align="right"
          placeholder="请输入岗位名称"
        />
        <van-field
          v-model="detailsList[10].value"
          rows="1"
          autosize
          :label="detailsList[10].label"
          input-align="right"
          is-link
          @click="jobSHow = true"
        />
        <van-field
          v-model="detailsList[11].value"
          rows="1"
          autosize
          :label="detailsList[11].label"
          input-align="right"
          is-link
          @click="statusShow = true"
        />
        <van-field
          v-model="detailsList[12].value"
          rows="3"
          autosize
          :label="detailsList[12].label"
          type="textarea"
          placeholder="请输入..."
        />
        <van-field
          v-model="detailsList[13].value"
          rows="3"
          autosize
          :label="detailsList[13].label"
          type="textarea"
          placeholder="请输入..."
        />
      </van-cell-group>
      <div class="mine-out">
        <van-button type="default" @click="addInfo()">保存</van-button>
      </div>
    </div>
    <van-action-sheet v-model="addressShow">
      <van-area :area-list="areaList" @cancel="cancel" @confirm="confirm" />
    </van-action-sheet>
    <van-action-sheet
      v-model="educationShow"
      :actions="educationActions"
      @select="onSelect"
    >
    </van-action-sheet>
    <van-action-sheet v-model="jobSHow">
      <van-area
        :area-list="areaList"
        @cancel="cancelJob"
        @confirm="confirmJob"
      />
    </van-action-sheet>
    <van-action-sheet
      v-model="statusShow"
      :actions="statusActions"
      @select="onSelectstatus"
    >
    </van-action-sheet>
  </div>
</template>
<script>
import mine from "../../../../controller/mine";
export default {
  name: "feedBack",
  components: {},
  data() {
    return {
      addressShow: false,
      educationShow: false,
      jobSHow: false,
      areaList: {},
      statusShow: false,
      eregionCode: "",
      educationActions: [
        { name: "博士" },
        { name: "硕士" },
        { name: "本科" },
        { name: "高中" },
        { name: "初中" },
        { name: "小学" },
        { name: "其他" }
      ],
      statusActions: [{ name: "在职" }, { name: "离职" }],
      detailsList: [
        {
          label: "照片",
          value: ''
        },
        {
          label: "姓名",
          value: ""
        },
        {
          label: "手机号",
          value: ""
        },
        {
          label: "身份证号",
          value: ""
        },
        {
          label: "年龄",
          value: ""
        },
        {
          label: "性别",
          value: "1"
        },
        {
          label: "户籍所在地",
          value: ""
        },
        {
          label: "户籍详细地址",
          value: ""
        },
        {
          label: "最高学历",
          value: ""
        },
        {
          label: "求职岗位",
          value: ""
        },
        {
          label: "就业地区",
          value: ""
        },
        {
          label: "目前状态",
          value: ""
        },
        {
          label: "工作经历",
          value: ""
        },
        {
          label: "自我介绍",
          value: ""
        }
      ]
    };
  },
  computed: {},
  created() {},
  mounted() {
    this.getInfo();
    this.gettree();
    this.detailsList[0].value = sessionStorage["resumeImg"] ? sessionStorage["resumeImg"] : sessionStorage["resumeInfo"] ? JSON.parse(sessionStorage["resumeInfo"]).headImage : ''
  },
  beforeDestroy() {
    sessionStorage.setItem("resumeImg", "");
  },
  methods: {
    goav(val){
            this.$router.push({path:'/work/myResume/updateHeadImg',query:{id:val}})
        },
    gettree() {
      let obj = {
        province_list: {},
        city_list: {},
        county_list: {}
      };
      mine.region_v1_findTree().then(res => {
        if (res.code == "0") {
          if (res.datas && res.datas.length > 0) {
            res.datas.forEach(item => {
              obj.province_list[item.regionCode] = item.regionName;
              if (item.children && item.children.length > 0) {
                item.children.forEach(item1 => {
                  obj.city_list[item1.regionCode] = item1.regionName;
                  if (item1.children && item1.children.length > 0) {
                    item1.children.forEach(item2 => {
                      obj.county_list[item2.regionCode] = item2.regionName;
                    });
                  }
                });
              }
            });
          }
          this.areaList = obj;
        } else {
          this.$toast(res.msg);
        }
      });
    },
    getInfo() {
      if (!sessionStorage["resumeInfo"]) {
        return;
      }
      let resumeInfo = JSON.parse(sessionStorage["resumeInfo"]);
      this.detailsList[0].value = resumeInfo.headImage;
      this.detailsList[1].value = resumeInfo.username;
      this.detailsList[2].value = resumeInfo.phone;
      this.detailsList[3].value = resumeInfo.idcardNo;
      this.detailsList[4].value = resumeInfo.age;
      this.detailsList[5].value = resumeInfo.gender.toString();
      this.detailsList[6].value = resumeInfo.rregionName;
      this.detailsList[7].value = resumeInfo.address;
      this.detailsList[8].value =
        resumeInfo.degree == 1
          ? "博士"
          : resumeInfo.degree == 2
          ? "硕士"
          : resumeInfo.degree == 3
          ? "本科"
          : resumeInfo.degree == 4
          ? "高中"
          : resumeInfo.degree == 5
          ? "初中"
          : resumeInfo.degree == 6
          ? "小学"
          : "其他";
      this.detailsList[9].value = resumeInfo.postName;
      this.detailsList[10].value = resumeInfo.eregionName;
      this.detailsList[11].value =
        resumeInfo.curStatus == 1
          ? "在职"
          : resumeInfo.curStatus == 2
          ? "离职"
          : "";
      this.detailsList[12].value = resumeInfo.experience;
      this.detailsList[13].value = resumeInfo.introduction;
    },
    addInfo() {
      if (sessionStorage["resumeInfo"]) {
        this.update();
        return;
      }
      let data = {
        address: this.detailsList[7].value,
        age: this.detailsList[4].value,
        birthDate: "",
        createdBy: "",
        creationDate: "",
        curStatus:
          this.detailsList[11].value == "在职"
            ? 1
            : this.detailsList[11].value == "离职"
            ? 2
            : "",
        degree:
          this.detailsList[8].value == "博士"
            ? 1
            : this.detailsList[8].value == "硕士"
            ? 2
            : this.detailsList[8].value == "本科"
            ? 3
            : this.detailsList[8].value == "高中"
            ? 4
            : this.detailsList[8].value == "初中"
            ? 5
            : this.detailsList[8].value == "小学"
            ? 6
            : 0,
        eregionName: this.detailsList[6].value.replace(/-/g,''),
        eregionCode: this.eregionCode ? this.eregionCode.replace(/-/g,',') : localStorage["resumeInfo"] ? JSON.parse(localStorage["resumeInfo"]).rregionCode : '',
        experience: this.detailsList[12].value,
        gender: this.detailsList[5].value,
        headImage: this.detailsList[0].value,
        id: "",
        idcardNo: this.detailsList[3].value,
        introduction: this.detailsList[13].value,
        lastUpdateDate: "",
        lastUpdatedBy: JSON.parse(localStorage["userInfo"]).currentUser.id,
        phone: this.detailsList[2].value,
        postName: this.detailsList[9].value,
        resumeCode: "",
        rregionCode: this.rregionCode ? this.rregionCode.replace(/-/g,',') : localStorage["resumeInfo"] ? JSON.parse(localStorage["resumeInfo"]).rregionCode :'',
        rregionName: this.detailsList[10].value.replace(/-/g,''),
        username: this.detailsList[1].value
      };
      mine.training_resume(data).then(res => {
        if (res.code == "0") {
          this.$toast("保存成功!");
          this.$router.push({ path: "/work/myResume/myResumeAdd" });
        } else {
          this.$toast(res.msg);
        }
      });
    },
    update() {
      let data = {
        address: this.detailsList[7].value,
        age: this.detailsList[4].value,
        birthDate: "",
        createdBy: "",
        creationDate: "",
        curStatus:
          this.detailsList[11].value == "在职"
            ? 1
            : this.detailsList[11].value == "离职"
            ? 2
            : "",
        degree:
          this.detailsList[8].value == "博士"
            ? 1
            : this.detailsList[8].value == "硕士"
            ? 2
            : this.detailsList[8].value == "本科"
            ? 3
            : this.detailsList[8].value == "高中"
            ? 4
            : this.detailsList[8].value == "初中"
            ? 5
            : this.detailsList[8].value == "小学"
            ? 6
            : 0,
        eregionName: this.detailsList[6].value.replace(/-/g,''),
        eregionCode: this.eregionCode ? this.eregionCode.replace(/-/g,',') : localStorage["resumeInfo"] ? JSON.parse(localStorage["resumeInfo"]).rregionCode : '',
        experience: this.detailsList[12].value,
        gender: this.detailsList[5].value,
        headImage: this.detailsList[0].value,
        id: JSON.parse(sessionStorage["resumeInfo"]).id,
        idcardNo: this.detailsList[3].value,
        introduction: this.detailsList[13].value,
        lastUpdateDate: "",
        lastUpdatedBy: JSON.parse(localStorage["userInfo"]).currentUser.id,
        phone: this.detailsList[2].value,
        postName: this.detailsList[9].value,
        resumeCode: JSON.parse(sessionStorage["resumeInfo"]).resumeCode,
        rregionCode: this.rregionCode ? this.rregionCode.replace(/-/g,',') : localStorage["resumeInfo"] ? JSON.parse(localStorage["resumeInfo"]).rregionCode :'',
        rregionName: this.detailsList[10].value.replace(/-/g,''),
        username: this.detailsList[1].value
      };
      mine.training_resume_update(data).then(res => {
        if (res.code == "0") {
          this.$toast("更新成功!");
          this.$router.push({ path: "/work/myResume/myResumeAdd" });
        } else {
          this.$toast(res.msg);
        }
      });
    },
    back() {
      sessionStorage.setItem("resumeInfo", "");
      this.$router.go(-1);
    },
    showAddress() {
      this.addressShow = true;
    },
    confirm(val) {
      this.addressShow = false;
      this.eregionCode = val[0].code + "-" + val[1].code + "-" + val[2].code;
      this.detailsList[6].value =
        val[0].name + "-" + val[1].name + "-" + val[2].name;
    },
    cancel() {
      this.addressShow = false;
    },
    confirmJob(val) {
      this.jobSHow = false;
      this.rregionCode = val[0].code + "-" + val[1].code + "-" + val[2].code;
      this.detailsList[10].value =
        val[0].name + "-" + val[1].name + "-" + val[2].name;
    },
    cancelJob() {
      this.jobSHow = false;
    },
    onSelect(item) {
      this.educationShow = false;
      this.detailsList[8].value = item.name;
    },
    onSelectstatus(item) {
      this.statusShow = false;
      this.detailsList[11].value = item.name;
    }
  }
};
</script>
<style lang="scss">
#addResume {
  background: #fff;
  .mine-out {
    padding: 50px 0;
    button {
      width: 80%;
      height: 80%;
      margin: auto;
      display: block;
      font-size: 20px;
      color: #fff;
      letter-spacing: 0;
      text-align: center;
      background: #dc4630;
      border-radius: 20px;
    }
  }
  textarea {
    background-color: #f5f5f5;
  }
  .van-radio-group {
    display: flex;
    padding-left: 140px;
  }
}
</style>
